﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tp.GUI.Controller;
using TpBaseObjects.Objects;

namespace Tp.GUI.Dialog {
    public partial class AbrLiefControllForm : Form {

        #region Members

        private AbrLiefController controller;
        
        #endregion

        #region Constructor

        public AbrLiefControllForm(List<AbrLiefRowObj> details) {
            InitializeComponent();
            this.controller = new AbrLiefController(this);
            
            foreach (AbrLiefRowObj row in details) {
                row.PropertyChanged += new PropertyChangedEventHandler(this.controller.ChangedDetailsProperties);
            }
            this.MyDetailsModel = details;
            this.controller.LoadModels();
            
            SetFormEventHandler();
            SetFormDataSource();
            SetFormDefaultValues();
            ShowTabControl(0);
        }

        #endregion

        #region Properties

        public AbrLiefModelObj MyModel {
            get;
            set;
        }

        public List<AbrLiefRowObj> MyDetailsModel {
            get;
            set;
        }

        public List<AbrLiefRowObj> DetailsForMarkup {
            get;
            set;
        }

        public bool Weiter {
            get;
            set;
        }

        public bool Cancel {
            get;
            set;
        }

        #endregion

        #region Methods

        private void SetFormDataSource() {
            this.bsAbrRowModel.DataSource = this.MyDetailsModel;
            this.bsMyModel.DataSource = this.MyModel;
        }

        private void SetFormEventHandler() {
            this.FormClosing += new FormClosingEventHandler(this.controller.BeforeCloseMyForm);
            this.btnWeiter.Click += new EventHandler(this.controller.Weiter);
            this.tabControl1.SelectedIndexChanged += new EventHandler(this.controller.ChangePageSelectedIndex);
        }

        private void SetFormDefaultValues() {
            this.Cancel = true;
            this.Weiter = false;
        }

        public void ShowTabControl(int currentPage) {
            this.tabControl1.SelectTab(currentPage);
        }

        #endregion


    }

}
